#include <iostream>
#include <unordered_map>
#include <string>

bool isNatural(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

std::string numberName(std::string word) {
    std::unordered_map<std::string, std::string> numberMap = {
        {"zero", "0"}, {"one", "1"},
        {"two", "2"}, {"three", "3"},
        {"four", "4"}, {"five", "5"},
        {"six", "6"}, {"seven", "7"},
        {"eight", "8"}, {"nine", "9"}
    };
    return numberMap[word];
}

int nearestPrime(int n) {
    if (n < 2) {
        return 2;
    }
    int l = n - 1;
    while (!isNatural(l)) {
        l -= 1;
    }
    int w = n + 1;
    while (!isNatural(w)) {
        w += 1;
    }
    if (n - l <= w - n) {
        return l;
    } else {
        return w;
    }
}

int main() {
    std::string line;
    std::getline(std::cin, line);
    std::istringstream iss(line);
    std::vector<std::string> words{std::istream_iterator<std::string>{iss},
                                   std::istream_iterator<std::string>{}};

    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    std::string numStr;
    for (const auto &word : words) {
        numStr += numberName(word);
    }

    if (!std::all_of(numStr.begin(), numStr.end(), ::isdigit) || !(100 <= std::stoi(numStr) && std::stoi(numStr) <= 999)) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int num = std::stoi(numStr);
    std::cout << nearestPrime(num) << std::endl;

    return 0;
}